package yt.demo.appcommondb.vo;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import lombok.Data;

import java.util.List;

@Data
public class ConditionVO<T, V> {
    private SFunction<T, V> column;
    private String operator;
    private V value;
    private List<ConditionVO<T, V>> subConditions;  // 子条件，用于分组
    private String logicalOperator;  // AND/OR

    // 静态工厂方法，用于单一条件 (没有子条件)
    public static <T, V> ConditionVO<T, V> createCondition(SFunction<T, V> column, String operator, V value) {
        return new ConditionVO<>(column, operator, value);
    }

    // 静态工厂方法，用于子条件分组
    public static <T, V> ConditionVO<T, V> createConditionGroup(List<ConditionVO<T, V>> subConditions, String logicalOperator) {
        return new ConditionVO<>(subConditions, logicalOperator);
    }

    // 构造器，用于单一条件 (没有子条件)
    private ConditionVO(SFunction<T, V> column, String operator, V value) {
        this.column = column;
        this.operator = operator;
        this.value = value;
    }

    // 构造器，用于子条件分组
    private ConditionVO(List<ConditionVO<T, V>> subConditions, String logicalOperator) {
        this.subConditions = subConditions;
        this.logicalOperator = logicalOperator;
    }

    // 判断是否有子条件
    public boolean hasSubConditions() {
        return subConditions != null && !subConditions.isEmpty();
    }
}
